---@class Battle.EventArgs
local EventArgs = Battle.CreateClass("EventArgs")
Battle.EventArgs = EventArgs
local eventList = {}
---@class BattleEvent
local Event = Class("Event")
Event.__index = Event
function Event:Create(...)
    local e = eventList[self.__cname]
    if not e then
        local arg = Battle.EventArgs[self.__cname]
        if arg == nil then
            logError("找不到该事件Args "..self.__cname)
            return nil
        end
        e = arg.New()
        eventList[self.__cname] = e
    end
    e:OnCreate(...)
    return e
end
function Event:OnCreate() end

function Event:ToString()
    local str = "{"
    for k,v in pairs(self) do
        local tp = type(v)
        if tp ~= "function" then
            str = str..tostring(k).."="
            if k == "class" then
                str = str..self.__cname
            elseif tp == "table" and v.__cname == "Entity" then
                str = str..v.id
            elseif k == "skill" then
                str = str..v.skillId
            elseif k == "buff" then
                str = str..v:ToString()
            else
                str = str..tostring(v)
            end
            str = str..","
        end
    end
    str = str.sub(str,1,-2).."}"
    return str
end


---@return BattleEvent
local function CreateEvent(name)
    local e = Class(name,Event)
    EventArgs[name] = e
    return e
end


-------------------------------sub event-------------------------------
---@class Battle.EntityArgs:BattleEvent
local EntityArgs = CreateEvent("EntityArgs")
EventArgs.EntityArgs = EntityArgs
function EntityArgs:OnCreate(entity)
    ---@type Battle.Entity
    self.sender = entity
end
---@class Battle.EntityHpChangeArgs:BattleEvent
local EntityHpChangeArgs = CreateEvent("EntityHpChangeArgs")
EventArgs.EntityHpChangeArgs = EntityHpChangeArgs
function EntityHpChangeArgs:OnCreate(sender,attacker)
    ---@type Battle.Entity
    self.sender = sender
    ---@type Battle.Entity
    self.attacker = attacker
end
---@class Battle.EntityDamageShowArgs:BattleEvent
local EntityDamageShowArgs = CreateEvent("EntityDamageShowArgs")
EventArgs.EntityDamageShowArgs = EntityDamageShowArgs
function EntityDamageShowArgs:OnCreate(sender,damage,damageShowType)
    ---@type Battle.Entity
    self.sender = sender
    self.damage = damage
    self.damageShowType = damageShowType
end
---@class Battle.BattleFinishedArgs:BattleEvent
local BattleFinishedArgs = CreateEvent("BattleFinishedArgs")
EventArgs.BattleFinishedArgs = BattleFinishedArgs
function BattleFinishedArgs:OnCreate(battleResult)
    self.battleResult = battleResult
end
---@class Battle.BattleStageChangeArgs:BattleEvent
local BattleStageChangeArgs = CreateEvent("BattleStageChangeArgs")
EventArgs.BattleStageChangeArgs = BattleStageChangeArgs
function BattleStageChangeArgs:OnCreate(stage)
    self.stage = stage
end
---@class Battle.BattleEnergyUpdateArgs:BattleEvent
local BattleEnergyUpdateArgs  = CreateEvent("BattleEnergyUpdateArgs")
EventArgs.BattleEnergyUpdateArgs = BattleEnergyUpdateArgs
function EventArgs.BattleEnergyUpdateArgs :OnCreate(energy,max)
    self.energy = energy
    self.max = max
end
---@class Battle.BattleActionCountUpdateArgs:BattleEvent
local BattleActionCountUpdateArgs = CreateEvent("BattleActionCountUpdateArgs")
EventArgs.BattleActionCountUpdateArgs = BattleActionCountUpdateArgs
function EventArgs.BattleActionCountUpdateArgs:OnCreate(action,actionMax)
    self.action = action
    self.max = actionMax
end
---@class Battle.HandCardUseArgs:BattleEvent
local HandCardUseArgs = CreateEvent("HandCardUseArgs")
EventArgs.HandCardUseArgs = HandCardUseArgs
function HandCardUseArgs:OnCreate(card)
    ---@type Battle.Card
    self.card = card
end
--region skill args
---@class SkillArgs :BattleEvent
local SkillArgs = CreateEvent("SkillArgs")
EventArgs.SkillArgs = SkillArgs
function SkillArgs:OnCreate(skill)
    ---@type Battle.Entity
    self.sender = skill.actor
    ---@type Battle.Skill
    self.skill = skill
end
---@class SkillCdChangeArgs:BattleEvent
local SkillCdChangeArgs = CreateEvent("SkillCdChangeArgs")
EventArgs.SkillCdChangeArgs = SkillCdChangeArgs
function SkillCdChangeArgs:OnCreate(skill,cd,maxCd)
    ---@type Battle.Entity
    self.sender = skill.actor
    ---@type Battle.Skill
    self.skill = skill
    ---@type Battle.Entity
    self.skillCd = cd
    self.skillMaxCd = maxCd
end
--endregion skill args

---@class BulletArgs:battle.BattleEvent
local BulletArgs = CreateEvent("BulletArgs")
EventArgs.BulletArgs = BulletArgs
function BulletArgs:OnCreate(bullet)
    ---@type Battle.Bullet
    self.bullet = bullet
end
---@class AnimatorPlayArgs:battle.BattleEvent
local AnimatorPlayArgs = CreateEvent("AnimatorPlayArgs")
EventArgs.AnimatorPlayArgs = AnimatorPlayArgs
function AnimatorPlayArgs:OnCreate(animName,skillId)
    self.animName = animName
    self.skillId = skillId
end

EventArgs.StartPathFindArgs = CreateEvent("StartPathFindArgs")
function EventArgs.StartPathFindArgs:OnCreate(pos)
    self.pos = pos
end

---@class Battle.EntityDeadArgs
local EntityDeadArgs = CreateEvent("EntityDeadArgs")
EventArgs.EntityDeadArgs = EntityDeadArgs
function EntityDeadArgs:OnCreate(dead,attacker)
    ---@type Battle.Entity
    self.dead = dead
    ---@type Battle.Entity
    self.attacker = attacker
end
---@class Battle.HitArgs:BattleEvent
local HitArgs = CreateEvent("HitArgs")
EventArgs.HitArgs = HitArgs
---@param damageData Battle.DamageData
function HitArgs:OnCreate(damageData)
    ---@type Battle.DamageData
    self.damageData = damageData
end
---@class Battle.EntityAttributeChangeArgs:BattleEvent
local EntityAttributeChangeArgs = CreateEvent("EntityAttributeChangeArgs")
EventArgs.EntityAttributeChangeArgs = EntityAttributeChangeArgs
function EntityAttributeChangeArgs:OnCreate(sender,oldAttrList,curAttrList)
    self.sender = sender
    self.oldAttrList = oldAttrList
    self.curAttrList = curAttrList
end
---@class Battle.EntityEffectStateChangeArgs:BattleEvent
local EntityEffectStateChangeArgs = CreateEvent("EntityEffectStateChangeArgs")
EventArgs.EntityEffectStateChangeArgs = EntityEffectStateChangeArgs
function EntityEffectStateChangeArgs:OnCreate(sender,stateId,isAdd)
    self.sender = sender
    self.stateId = stateId
    self.isAdd = isAdd
end

---@class Battle.EntitySignChangeArgs:BattleEvent
local EntitySignChangeArgs = CreateEvent("EntitySignChangeArgs")
EventArgs.EntitySignChangeArgs = EntitySignChangeArgs
function EntitySignChangeArgs:OnCreate(sender,signId,isAdd)
    ---@type Battle.Entity
    self.sender = sender
    self.signId = signId
    self.isAdd = isAdd
end

---@class Battle.BufferArgs:BattleEvent
local BufferArgs = CreateEvent("BufferArgs")
EventArgs.BufferArgs = BufferArgs
function BufferArgs:OnCreate(sender ,buff)
    ---@type Battle.Entity
    self.sender = sender
    ---@type Battle.Buffer
    self.buff = buff
end

EventArgs.ActorHandMoveArgs = CreateEvent("ActorHandMoveArgs")
function EventArgs.ActorHandMoveArgs:OnCreate(sender,x,y,z)
    ---@type Battle.Entity
    self.sender = sender
    self.x = x
    self.y = y
    self.z = z
end
EventArgs.ShowPutAreaEffectArgs = CreateEvent("ShowPutAreaEffectArgs")
function EventArgs.ShowPutAreaEffectArgs:OnCreate(isShow)
    self.isShow = isShow
end

EventArgs.ActorEnterGrassArgs = CreateEvent("ActorEnterGrassArgs")
function EventArgs.ActorEnterGrassArgs:OnCreate(sender,grassId,isEnterGrass)
    self.grassId = grassId
    self.isEnterGrass = isEnterGrass
    ---@type Battle.Entity
    self.sender = sender
end
---@class Battle.WeatherStartArgs:BattleEvent
local WeatherStartArgs = CreateEvent("WeatherStartArgs")
EventArgs.WeatherStartArgs = WeatherStartArgs
function WeatherStartArgs:OnCreate(id)
    self.weatherId = id
end




